// pages/mine/shop/mycard/paytype.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    info: null,
    mycard_id: '',
    type:'',
    meal_log_good:0,
  },
  backto: function (e) {
    wx.navigateBack({})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var show = 0;
    var hide = 0;
    console.log(options);
    var title='';
    if (options.type == 1){
        title='金额支付';
        show=1;
        hide=0;
  }else{
    title='套餐支付';
    show=0;
    hide = 1;
  }
    that.setData({
      mycard_id: options.mycard_id,
       type:options.type,
       title:title,
       show:show,
       hide:hide,

    });

  },
  // 获取 会员卡的相关信息
  getCard: function () {
    let that = this;
    app.ihttpGet('https://www.58zltc.com/api.php/MyCard/payType/openid/' + app.globalData.openid + '/card_id/' + that.data.mycard_id+'/type/'+that.data.type, function (res) {
      that.setData({
       list: res.data.list,
       input_list:res.data.form,
        type: that.data.type,
        add_url: res.data.form.add_url,
      })
      wx.hideLoading();
    });
  },
  bindChange: function (e) {
    var data = e.currentTarget.dataset;
    var list = this.data.input_list;
    list.forEach(function (item, idx) {
      if (item.title == data.title) {
        list[idx].value = e.detail.value;
      }
    })
    this.setData({
      input_list: list
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;

    wx.showLoading({
      title: '加载中…',
    })
    this.getCard();
  },
  radiochange: function (e) {
    var recharge_id = '';
    console.log(e.detail.value);
    this.data.meal_log_good = e.detail.value;

  },
  formSubmit: function (e) {
    app.addFormId(e.detail.formId);
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    var post_data = e.detail.value;
    var data = this.data;
    let that = this;

    post_data.openid = app.globalData.openid;
    post_data.card_id = data.mycard_id;
    post_data.type = data.type;
    post_data.meal_log_good=data.meal_log_good;
    app.ihttpPost(data.add_url, post_data, function (res) {
      if (res.data.err_code > 0) {
        wx.showToast({
          title: res.data.err_msg,
        })
      } else {
        wx.showToast({
          title: res.data.err_msg,
          icon: 'success'
        })
        setTimeout(function () {
          wx.navigateBack({})
        }, 500)
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  hiden_agreement: function () {
    var that = this
    this.setData({
      showShopJoinAgreement: 0
    })
    wx.navigateTo({
      url: './card/joincard?shop_id=' + that.data.shop_id,
    })
  }
})